package Company;

public class Company {

    private Staff[] allStaff = new Staff[50];

    // 添加一个员工
    public void addStaff(Staff staff) {
        for (int i = 0; i < 50; i++) {
            if (this.allStaff[i] == null) {
                this.allStaff[i] = staff;
                return;
            }
        }
    }

    // 通过员工的名字删除员工
    public void deleteStaff(Staff staff) {
        for (int i = 0; i < 50; i++) {
            if (this.allStaff[i].name == staff.name) {
                this.allStaff[i] = null;
            } else
                System.out.println("查无此人！");
        }
    }

    // 通过员工的名字来显示员工的工资。
    public void printSalary(Staff staff) {
        for (int i = 0; i < 50; i++) {
            if (this.allStaff[i].name == staff.name) {
                System.out.println(this.allStaff[i].totalSalary());
            } else
                System.out.println("查无此人！");
        }
    }

    // 输出所有员工的工资和
    public void salarySum() {
        double result = 0;
        for (int i = 0; i < 50; i++) {
            if (this.allStaff[i] != null) {
                result += this.allStaff[i].totalSalary();
            }
        }
        System.out.println("所有员工的工资和是" + result);
    }

}
